package com.lfnyxy.service.org.imp;

import com.lfnyxy.dao.org.UserFunctionDao;
import com.lfnyxy.entity.org.UserFunctionDetailEntity;
import com.lfnyxy.entity.org.UserFunctionEntity;
import com.lfnyxy.query.org.UserFunctionQuery;
import com.lfnyxy.service.org.UserFunctionService;
import com.lfnyxy.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserFunctionServiceImp implements UserFunctionService {
    @Autowired
    public UserFunctionDao userFunctionDao;

    public int CreateItem(UserFunctionEntity entity) {
        if (entity != null) {
            userFunctionDao.CreateItem(entity);
            return entity.getId();
        } else {
            return 0;
        }
    }

    public int UpdateItem(UserFunctionEntity entity) {
        if (entity != null) {
            userFunctionDao.UpdateItem(entity);
            return entity.getId();
        } else {
            return 0;
        }
    }

    public List<UserFunctionEntity> QueryPageList(UserFunctionQuery query) {
        int count = userFunctionDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return userFunctionDao.QueryPageList(query);
        }
        return null;
    }

    public List<UserFunctionEntity> QueryAll() {
        return userFunctionDao.QueryAll();
    }

    public UserFunctionEntity QueryItem(int Id) {
        if (Id > 0) {
            return userFunctionDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public UserFunctionEntity QueryByRole(int roleId) {
        if (roleId > 0) {
            return userFunctionDao.QueryByRole(roleId);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return userFunctionDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(UserFunctionEntity entity) {
        if (entity != null) {
            return userFunctionDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }

    public void DeleteFunctionDetail(int funId) {
        if(funId > 0){
            userFunctionDao.DeleteFunctionDetail(funId);
        }
    }

    public void CreateFunctionDetail(UserFunctionDetailEntity item) {
        if(item != null && item.getFuntionId() > 0){
            userFunctionDao.CreateDetail(item);
        }
    }

    public List<PageVo> QueryPageVoByRoleId(int roleId){
        if(roleId > 0){
            return userFunctionDao.QueryPageVoByRoleId(roleId);
        }
        else{
            return null;
        }
    }
}